﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL; 
using KPIS.DBM;

using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class InqStdScoreComboBLL

    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);


        public DataTable ListInqStdScoreCombo()
        {

            try
            {
                string sql;
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@record_status", SystemInfo._ActiveRecordStatus);

                sql = "SELECT std_dtls_seq, score_level_name "
                    + " FROM hrm_apr_std_score_dtls"
                    + " WHERE record_status = @record_status";
                DataSet ds = new DataSet();
                DataTable dt;
               
                dbManager.Open();
                ds = dbManager.ExecuteDataSet(CommandType.Text, sql);
                dt = ds.Tables[0];
                DataRow dr = dt.NewRow();
                dr["std_dtls_seq"] = "-1";
                dr["score_level_name"] = "...ระดับผลการประเมินหลัก...";
                dt.Rows.InsertAt(dr, 0);
                return dt;
            }
            catch(Exception ex)
            {
                return null;
                // throw new Exception("");
            }
            finally
            {
                dbManager.Dispose();  
            }
        }

        public string[] GetMaxMin(int std_dtls_seq)
        {
            string[] scor = new string[2];
            try
            {
                dbManager.CreateParameters(2);
                dbManager.AddParameters(0, "@std_dtls_seq", std_dtls_seq);
                dbManager.AddParameters(1, "@record_status", SystemInfo._ActiveRecordStatus);
                
                string sql;
                sql = "SELECT SCORE_MAX, SCORE_MIN "
                    + " FROM HRM_APR_STD_SCORE_DTLS"
                    + " WHERE RECORD_STATUS = @record_status"
                        + " AND STD_DTLS_SEQ =@std_dtls_seq";                

                DataSet ds;
                DataTable dt;
                ds = new DataSet();
                dbManager.Open();
                ds = dbManager.ExecuteDataSet(CommandType.Text, sql);
                dt = ds.Tables[0];
                if (dt.Rows.Count == 1)
                {
                    scor[0] = dt.Rows[0]["SCORE_MIN"].ToString();
                    scor[1] = dt.Rows[0]["SCORE_MAX"].ToString();
                }
                
            }
            catch (Exception ex)
            {

                return null;

            }
            finally
            {
                dbManager.Dispose();
            }

            return scor;
        }
    }
}
